<%--
  - Author		:	Jaewon Choi
  - Date			:
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty gcm}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd"
				});
			});

			function validation(){
				try{
					with(document.frm){
						if((sendDate.value).replace(/\s/g, '') == ""){
							alert("[발송일]은 필수 입력 항목입니다.");
							sendDate.focus();
							return false;
						}
						sendTime.value = sendDate.value+" "+sendHour.value+":"+sendMin.value+":00";
						
						if((title.value).replace(/\s/g, '') == ""){
							alert("[제목]은 필수 입력 항목입니다.");
							title.focus();
							return false;
						}
						
						if(($(".message").val()).replace(/\s/g, '') == ""){
							alert("[내용]은 필수 입력 항목입니다.");
							$(".message").focus();
							return false;
						}
						
					}
					
				}catch(err){
					return false;
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}
		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					Android푸시메시지 >  ${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/gcm/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="searchBeginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="searchEndTime" value="${param.searchEndTime}" />
					<input type="hidden" name="idx" value="${gcm.idx}">
					
					<table class="frmTbl">
						<colgroup>
							<col width="130px;" />
							<col width="*" />
						</colgroup>
						<tbody>
							<c:if test="${not empty gcm}">
								<tr>
									<th>상태</th>
									<td>
										<c:choose>
											<c:when test="${gcm.status eq -1}">발송실패</c:when>
											<c:when test="${gcm.status eq 0}">발송준비</c:when>
											<c:when test="${gcm.status eq 1}">발송대기</c:when>
											<c:when test="${gcm.status eq 2}">발송완료</c:when>
											<c:otherwise>
												${gcm.status}
											</c:otherwise>
										</c:choose>
									</td>
								</tr>
							</c:if>
							<tr>
								<th>발송일시 *</th>
								<td>
									<c:catch var="e">
										<fmt:parseDate var="sendTime" pattern="yyyy-MM-dd HH:mm:ss" value="${gcm.sendTime}" />
										<fmt:formatDate var="sendDate" value="${sendTime}" pattern="yyyy-MM-dd" />
										<fmt:formatDate var="sendHour" value="${sendTime}" pattern="HH" />
										<fmt:formatDate var="sendMin" value="${sendTime}" pattern="mm" />
									</c:catch>
									<c:if test="${not empty e}">
										<c:set var="sendTime" value="${gcm.sendTime}" />
									</c:if>
									<input type="hidden" name="sendTime" value="${gcm.sendTime}" />
									<input type="text" class="date" name="sendDate" readonly="readonly" value="${sendDate}" />
									<select name="sendHour">
										<c:forEach var="i" begin="0" end="23" step="1">
											<fmt:formatNumber var="hour" value="${i}" pattern="00" />
											<option value="${hour}" <c:if test="${sendHour eq i}"> selected="selected" </c:if>>${hour}</option>
										</c:forEach>
									</select> :
									<select name="sendMin">
										<option value="00" <c:if test="${sendMin eq '00'}"> selected="selected" </c:if>>00</option>
										<option value="30" <c:if test="${sendMin eq '30'}"> selected="selected" </c:if>>30</option>
									</select>
								</td>
							</tr>
							<tr>
								<th>제목 *</th>
								<td>
									<input type="text" name="title" value="${gcm.title}" maxlength="12" style="width:660px;" />
								</td>
							</tr>
							<c:forEach var="gcmData" items="${gcmDataList}">
								<c:choose>
									<c:when test="${gcmData.key eq 'subtitle'}">
										<c:set var="subtitle" value="${gcmData.data}" />
									</c:when>
									<c:when test="${gcmData.key eq 'message'}">
										<c:set var="message" value="${gcmData.data}" />
									</c:when>
								</c:choose>
							</c:forEach>
							<tr>
								<th>알림바 문구</th>
								<td>
									<input type="hidden" name="key" value="subtitle" />
									<input type="text" name="data" class="subtitle" value="${subtitle}" maxlength="50" style="width:660px;" />
								</td>
							</tr>
							<tr>
								<th>내용 *</th>
								<td>
									<input type="hidden" name="key" value="message" />
									<input type="text" name="data" class="message" value="${message}" maxlength="20" style="width:660px;" />
								</td>
							</tr>
						</tbody>
					</table>
					<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
					<input type="submit" class="btn" value="${fAct}" />
					<c:if test="${not empty gcm}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('삭제 하시겠습니까?')){document.removeFrm.submit();}" />
					</c:if>
				</form>
				<form name="listFrm" action="<c:url value="/gcm/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="beginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="endTime" value="${param.searchEndTime}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/gcm/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${gcm.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="beginTime" value="${param.searchBeginTime}" /> 
					<input type="hidden" name="endTime" value="${param.searchEndTime}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 